package com.atguigu.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author zhaoshuo
 * @ClassName RabbitmqConfig
 * @Description
 */
@Configuration
public class RabbitmqConfig {

    @Bean
    public Exchange test3Exchange() {
        return ExchangeBuilder.topicExchange("test3.exchange").ignoreDeclarationExceptions()
                .durable(true).build();
    }

    @Bean
    public Queue test3Queue() {
        return QueueBuilder.durable("test3.queue").deadLetterExchange("dead.exchange")
                .deadLetterRoutingKey("dead.msg").build();
    }

    @Bean
    public Binding test3Binding(Exchange test3Exchange, Queue test3Queue) {
        return BindingBuilder.bind(test3Queue).to(test3Exchange).with("test3.*").noargs();
    }


    @Bean
    public Exchange deadExchange() {
        return ExchangeBuilder.topicExchange("dead.exchange").ignoreDeclarationExceptions()
                .durable(true).build();
    }

    @Bean
    public Queue deadQueue() {
        return QueueBuilder.durable("dead.queue").ttl(15000).deadLetterExchange("delay.exchange")
                .deadLetterRoutingKey("delay.msg").build();
    }

    @Bean
    public Binding deadBinding(Exchange deadExchange, Queue deadQueue) {
        return BindingBuilder.bind(deadQueue).to(deadExchange).with("dead.msg").noargs();
    }


    @Bean
    public Exchange delayExchange() {
        return ExchangeBuilder.topicExchange("delay.exchange").ignoreDeclarationExceptions()
                .durable(true).build();
    }

    @Bean
    public Queue delayQueue() {
        return QueueBuilder.durable("delay.queue").build();
    }

    @Bean
    public Binding delayBinding(Exchange delayExchange, Queue delayQueue) {
        return BindingBuilder.bind(delayQueue).to(delayExchange).with("delay.msg").noargs();
    }
}